↜ Back to index Introduction to Numerical Analysis 1
Solution Lecture a6
Exercise 2
! Implementation of the midpoint method for the Lotka-Volterra system
implicit none
integer i, n
real h, t
real y(2), k(2)
= 0.1
h = 100 / h
n
! Initial data
= [10., 10.]
y print *, 0., y
do i = 1, n
= y + 0.5 * h * [1.1 * y(1) - 0.4 * y(1) * y(2), 0.1 * y(1) * y(2) - 0.4 * y(2)]
k = y + h * [1.1 * k(1) - 0.4 * k(1) * k(2), 0.1 * k(1) * k(2) - 0.4 * k(2)]
y
print *, i * h, y
enddo
end
Exercise 3
! Implementation of the midpoint method for the Lotka-Volterra system
! and finding the minimum and maximum of x and y
implicit none
integer i, j, n
real h, t
real y(2), k(2), ymin(2), ymax(2)
= 0.1
h = 100 / h
n
! Initial data
= [10., 10.]
y = y
ymax = y
ymin
do i = 1, n
= y + 0.5 * h * [1.1 * y(1) - 0.4 * y(1) * y(2), 0.1 * y(1) * y(2) - 0.4 * y(2)]
k = y + h * [1.1 * k(1) - 0.4 * k(1) * k(2), 0.1 * k(1) * k(2) - 0.4 * k(2)]
y
do j = 1, 2
= max(ymax(j), y(j))
ymax(j) = min(ymin(j), y(j))
ymin(j) enddo
enddo
print *, 'Minimum of x and y:', ymin
print *, 'Maximum of x and y:', ymax
end